package com.cgs.mongo.extractor;

import com.mongodb.client.MongoCursor;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;
import org.bson.BsonString;
import org.bson.Document;

/**
 * 纯打印提取器
 */
public class PrintCursorExtractor extends AbstractCursorExtractor<Void> {

    @Override
    protected Void mapIterable(MongoCursor<Object> iterator) {
        CursorExtractor.forEach(iterator, (bv, num) -> {
            System.out.println(bv);
            return null;
        });
        return null;
    }

    @Override
    protected Void mapLong(Long result) {
        System.out.println(result);
        return null;
    }

    @Override
    protected Void mapUpdateResult(UpdateResult result) {
        System.out.println(result.getMatchedCount());
        return null;
    }

    @Override
    protected Void mapDeleteResult(DeleteResult result) {
        System.out.println(result.getDeletedCount());
        return null;
    }

    @Override
    protected Void mapBsonString(BsonString result) {
        System.out.println(result.getValue());
        return null;
    }

    @Override
    protected Void mapDocument(Document result) {
        System.out.println(result.toJson());
        return null;
    }
}
